# CMake 最低版本号要求
cmake_minimum_required (VERSION 3.1)

# 项目信息
project (Demo9 VERSION 1.2) 

# 打印
message(STATUS ${PROJECT_VERSION})
message(STATUS ${PROJECT_VERSION_MAJOR})
message(STATUS ${PROJECT_VERSION_MINOR})
message (STATUS "STATUS: Demo9")
message (WARNING "WARNING: Demo9")

# 定义变量
set(HELLO hello)
message (STATUS ${HELLO})

# 流程、循环
option(USE_CURL "use libcurl" ON)
if(USE_CURL)
    message(STATUS "using lib curl")
else()
    message(STATUS "not using lib curl")
endif()

foreach(i 0 1 2 3)
    message(STATUS "foreach-1 is ${i}")
endforeach(i)

foreach(i RANGE 3)
    message(STATUS "foreach-2 is ${i}")
endforeach(i)

foreach(i RANGE 0 3 1)
    message(STATUS "foreach-3 is ${i}")
endforeach(i)

# macro宏定义与function函数
macro(FOO arg1 arg2 arg3)
    message(STATUS "this is arg1:${arg1}, ARGV0=${ARGV0}")  # ARGV#	#是一个下标，0指向第一个参数，累加
    message(STATUS "this is arg2:${arg2}, ARGV1=${ARGV1}")
    message(STATUS "this is arg3:${arg3}, ARGV2=${ARGV2}")
    message(STATUS "this is argc:${ARGC}")  # ARGC 实际参数的个数
    message(STATUS "this is args:${ARGV}, ARGN=${ARGN}")  # ARGV所有的定义时要求传入的参数，ARGN 多余的参数
    if(arg1 STREQUAL one)
        message(STATUS "this is arg1 one")
    else(arg1 STREQUAL p1)
        message(STATUS "this is arg1 p1")
    endif()
    if(ARGV2 STREQUAL "two")
        message(STATUS "this is arg2")
    endif()
    set(${arg1} nine)
    message(STATUS "after set arg1=${${arg1}}")
endmacro(FOO)

function(BAR arg1)
    message(STATUS "this is arg1:${arg1}, ARGV0=${ARGV0}")
    message(STATUS "this is argn:${ARGN}")
    if(arg1 STREQUAL first)
        message(STATUS "this is first")
    endif()
    set(arg1 ten)
    message(STATUS "after set arg1=${arg1}")
endfunction(BAR arg1)

set(p1 one)
set(p2 two)
set(p3 three)
set(p4 four)
set(p5 five)
set(p6 first)
set(p7 second)

FOO(${p1} ${p2} ${p3} ${p4} ${p5})
BAR(${p6} ${p7})
message(STATUS "after bar p6=${p6}")
